package com.xbts.screen.controller.screen;

import com.xbts.common.core.constant.CacheConstants;
import com.xbts.common.core.constant.Constants;
import com.xbts.common.core.enums.DateTypeEnum;
import com.xbts.common.core.enums.WorkshopTypeEnum;
import com.xbts.common.core.utils.StringUtils;
import com.xbts.common.core.web.controller.BaseController;
import com.xbts.common.core.web.domain.AjaxResult;
import com.xbts.common.core.web.domain.BaseHistogramResult;
import com.xbts.common.security.annotation.RequiresPermissions;
import com.xbts.screen.service.ISyntheticScreenServer;
import com.xbts.screen.service.IWeVirtualDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 大屏-产能
 */
@Api(tags = "大屏-产能")
@RequestMapping("/home")
@RestController
public class ScreenCapacityController extends BaseController {

    @Autowired
    public RedisTemplate redisTemplate;

    @Autowired
    private IWeVirtualDataService weVirtualDataService;

    @Autowired
    private ISyntheticScreenServer syntheticScreenServer;
    /**
     * 产能-详情-按时间类型
     */
    @ApiOperation("产能-详情-按时间类型")
    @RequiresPermissions("screen:capacity:detailsByDateType")
    @GetMapping("/capacityDetailsByDateType")
    public AjaxResult capacityDetailsByDateType(DateTypeEnum dateType){
        String showVirtualData = (String)redisTemplate.opsForValue().get(CacheConstants.SYS_SHOW_VIRTUAL_DATA);
        if (StringUtils.equals(showVirtualData, Constants.TRUE)){
            return success(weVirtualDataService.capacityDetailsByDateType(dateType));
        } else {
            BaseHistogramResult baseHistogramResult = syntheticScreenServer.capacityDetailsByDateType(dateType);
            if(baseHistogramResult == null){
                return success(weVirtualDataService.capacityDetailsByDateType(dateType));
            } else {
                return success(baseHistogramResult);
            }
        }

    }

    /**
     * 产能-车间详情-按时间类型
     */
    @ApiOperation("产能-车间详情-按时间类型")
    @RequiresPermissions("screen:capacity:workshop:detailsByDateType")
    @GetMapping("/capacityWorkshopDetailsByDateType")
    public AjaxResult capacityWorkshopDetailsByDateType(DateTypeEnum dateType, String value){
        BaseHistogramResult baseHistogramResult = syntheticScreenServer.capacityWorkshopDetailsByDateType(dateType, value);
        return success(baseHistogramResult);
    }

}
